package com.ziyear.nacos.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.Map;

@RestController
//@RefreshScope
public class NacosConfigController {
    @Value("${datasource.driver}")
    private String driver;
    @Value("${datasource.url}")
    private String url;
    @Value("${datasource.username}")
    private String username;
//    @Value("${datasource.password}")
    @NacosValue(value = "${datasource.password}", autoRefreshed = true)
    private String password;

    @RequestMapping("/nacos")
    public Object nacos() {
        Map<String, String> data = new LinkedHashMap<>();
        data.put("driver", driver);
        data.put("url", url);
        data.put("username", username);
        data.put("password", password);
        return data;
    }
}
